// Learn JavaScript:
//  - Created by zhanghejun
// 	- creation time ：  2021-08-31
//  - 

const verify = require('../../Utils/verify');
cc.Class({
    extends: cc.Component,

    properties: {
        ui_accont:cc.EditBox,
        ui_password:cc.EditBox
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {

    },

    // update (dt) {},
    onclick(event,customEventData){
        Global.AudioManager.playSound();
        if (customEventData == 'close'){
            this.removeLayer();
        }else{
            if (!this.ui_accont.string || !verify.enOrNum(this.ui_accont.string)){
                createTips('账号有误,请重新输入',Global.Code.FAIL);
                return;
            };
            if (!this.ui_password.string){
                createTips('请输入密码',Global.Code.FAIL);
                return;
            };
            this.register();
        }
    },
    register(){
        showWaiting(true);
        Global.HttpApi.register({username:this.ui_accont.string,password:this.ui_password.string},function(result){
            Global.NoticeManager.emitMessage('UpdateToken',result.data.userinfo.token);
            Global.NoticeManager.emitMessage('UpdateUserInfoPush',result.data.userinfo.token);
            createTips(result.msg,Global.Code.SUCCESS);
            setTimeout(function(){
                cc.director.loadScene("hallScence");
            },1000); 
        },function(res){
            showWaiting();
            createTips(res.msg,Global.Code.FAIL);
        });
    },
    removeLayer(){
        Global.LayerManager.remove('RegisterLayer');
    }
});
